import datetime
import calendar
import time

'''其它处理时间的模块
    datetime模块
    pytz模块
    dateutil模块
'''
class DateUtil:

    @staticmethod
    def get_current_datetime():
        return datetime.datetime.now()

    @staticmethod
    def get_current_date():
        return datetime.datetime.now().date()

    @staticmethod
    def get_current_time():
        return datetime.datetime.now().time()

    @staticmethod
    def time_interval():
        a = datetime.datetime(2016, 10, 20)
        print("===============")
        b = datetime.datetime(2015, 10, 20)
        x = (b-a).total_seconds()
        print(x)

    @staticmethod
    def strftime__():
        date = datetime.datetime.now()
        print(date.strftime("%Y-%m-%d %H:%M"))

    @staticmethod
    def strptime__():
        date = datetime.time.strptime('2014-08-15 10:27:36', "%Y-%m-%d %H:%M")
        print(type(date))

    @staticmethod
    def add(days=None, hours=None, seconds=None):
        date = datetime.datetime.now() + datetime.timedelta(days, hours, seconds)
        return date

    # def test_time():
    #     now_time = time.localtime(time.time())
    #     print now_time
    #     # print now_time["tm_year"]
    #     # 格式化时间
    #     print time.strftime("%Y-%m-%d %H:%M:%S",now_time)
    #     # 将时间转成时间戳
    #     a = "2016-11-30 14:24:22"
    #     print time.mktime(time.strptime(a, '%Y-%m-%d %H:%M:%S'))
    #
    #     #线程休眠5秒
    #     time.sleep(1)
    #
    #     # 获取日历
    #     print calendar.calendar(2016, w=2, l=1, c=6)    #返回年历
    #     print calendar.month(2016, 11)    #返回月历
    #     print calendar.isleap(2017)   # 是否闰年
    #     print calendar.leapdays(2003, 2020)   # 返回期间闰年总数


if __name__ == '__main__':
    """
    获取当前时间的7天前
    """
    DateUtil.add()